package com.cloud.charts4a.demo;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

/**
 * Abstract Chart Demo</p>
 * 
 * @version
 * <ol>
 * 	<li>2010/07/09 CloudTu：First Release</li>
 * </ol>  
 * 
 * @author cloudtu
 */
public abstract class AbstractChartDemo extends Activity {
	private static final int MENU_LINE_CHART = Menu.FIRST+1;
	private static final int MENU_TIME_CHART = Menu.FIRST+2;	
	private static final int MENU_CHART_CONFIG = Menu.FIRST+3;
	
	private Dialog chartConfigDialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		chartConfigDialog = createChartConfigDialog();
	}
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	super.onCreateOptionsMenu(menu);    	
    	menu.add(0, MENU_LINE_CHART, 0, R.string.lineChart);
    	menu.add(0, MENU_TIME_CHART, 0, R.string.timeChart);
    	menu.add(0, MENU_CHART_CONFIG, 0, R.string.chartConfig);
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
		case MENU_LINE_CHART:
			startActivity(new Intent(this, LineChartDemo.class));
			break;
		case MENU_TIME_CHART:
			startActivity(new Intent(this, TimeChartDemo.class));
			break;
		case MENU_CHART_CONFIG:
			chartConfigDialog.show();
			break;			
		}
		return false;
    }

    abstract protected Dialog createChartConfigDialog();
}
